package homework;

import java.util.Scanner;

public class StringBuilderDemo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        System.out.println("请输入5个单词:");
        for (int i = 0; i < 5; i++) {
            sb.append(scanner.next());
            if (i < 4) sb.append("-");
        }

        // 替换第三个单词
        int firstDash = sb.indexOf("-");
        int secondDash = sb.indexOf("-", firstDash + 1);
        sb.replace(firstDash + 1, secondDash, "middle");

        // 反转
        sb.reverse();
        System.out.println("结果: " + sb.toString());
    }
}
